package ua.nure.nguyen.bookstore.web.db;

import static ua.nure.nguyen.bookstore.web.db.constant.DbConstants.DAO_FACTORY_FCN;
import ua.nure.nguyen.bookstore.web.db.dao.DAO;
import ua.nure.nguyen.bookstore.web.db.dao.DAOFactory;
import ua.nure.nguyen.bookstore.web.db.entity.Book;
import ua.nure.nguyen.bookstore.web.db.entity.User;

public class Demo {

	public static void main(String[] args) throws Exception {
		DAOFactory
				.setDaoFactoryFCN(DAO_FACTORY_FCN);
		DAOFactory daoFactory = DAOFactory.getInstance();
		DAO<User> userDAO = daoFactory.getUserDAO();
		long id = userDAO.create(new User("test", "123456"));
		System.out.println(userDAO.read(id));

		userDAO.update(new User(id, "viet", "nguyen"));
		System.out.println(userDAO.read(id));

		userDAO.delete(id);
		System.out.println(userDAO.read(id));
		
		DAO<Book> bookDAO = daoFactory.getBookDAO();
		id = bookDAO.create(new Book("Harry Potter", "J. K. Rowling"));
		System.out.println(bookDAO.read(id));
		
		bookDAO.update(new Book(id, "Harry Potter", "V. Nguyen"));
		System.out.println(bookDAO.read(id));
		
//		bookDAO.delete(id);
//		System.out.println(bookDAO.read(id));
	}

}
